
<?php
include_once 'CF_Table.php';
class CF_TableEdPage extends CF_Table{

	var $actionpage;		
	var $editpage;
	var $ordervar = 'order';
    var $edit_link_text = 'Edit';
    var $delete_link_text = 'Delete';
    var $edit_prefix;
	var $trigger_param = 'sel';

	// Perhaps replace these with the set_url function
	function set_actionpage($pagename){
		$this->actionpage = $pagename;
	}	
	
	function set_editpage($pagename){
		$this->editpage = $pagename;
	}
	
	var $urls_info;

	function set_url($action,$url = '',$method = 'post',$params = null, $caption = null){
		$this->urls_info[$action]['url'] = $url;
		$this->urls_info[$action]['params'] = $params;		
		$this->urls_info[$action]['method'] = $method;	
		if(is_null($caption)){
			$this->urls_info[$action]['caption'] = $action;
		}else{
			$this->urls_info[$action]['caption'] = $caption;
		}
	}

	function _hash_to_hfields($params){
		$params = @array_merge($params, $this->keys);
		if(is_array($params)){
		foreach($params as $param=>$pvalue){
			$html .= "<input type='hidden' name='$param' value='$pvalue' /> ";
		}	
		}
	}
	
	function _hash_to_urlparams($params){
		$params = @array_merge($params, $this->keys);
		if(is_array($params)){
		foreach($params as $param=>$pvalue){
			$html .= $delimiter . $param . '=' . $pvalue;
			$delimiter = '&';
		}
		}
		return $html;
	}	
	
	// Overrides and Extension mehods	
	function make_row_end($row_num){
		$endstring .= "</tr>\n";
		return $endstring;
	}
	function action_button_form($action,$value = null){
			$html ="<form action='{$this->urls_info[$action]['url']}' method='{$this->urls_info[$action]['method']}' >
			
			<input type='submit' value='{$this->urls_info[$action]['caption']}' />\n";
			if(is_array($this->urls_info[$action]['params'])){
			foreach($this->urls_info[$action]['params'] as $param=>$pvalue){
				$html .= "<input type='hidden' name='$param' value='$pvalue' />\n ";
			}
			}
			$html .= "</form>";
			return $html;
			
	}

	function action_link($action,$value = null){
		return "<a href='{$this->urls_info[$action]['url']}?" . $this->_hash_to_urlparams($this->urls_info[$action]['params']) . "'>" . $this->urls_info[$action]['caption'] . "</a>";
				
	}	
	
	function make_delete($value, $column){
		return($this->action_button_form('delete'));
	}
	function make_edit($value, $column){
		return($this->action_link('edit',$value));
	}

	function old_make_edit($value, $column){
			return "<a href='$this->editpage?$this->trigger_param=$this->name&mode=Edit$this->keys_url_edit$this->referstring'>$this->edit_link_text</a>";
			
	}	
	
	function old_make_delete($value, $column){
			return "<a href='$this->actionpage?$this->trigger_param=$this->name&mode=Delete$this->keys_url_act$this->referstring'>$this->delete_link_text</a>";	
	}

	// mostly here just to save the code...
		function make_PopUpEdit($keyvalue, $column){
			return("<a href=\"javascript:makePopUpEdit('customers_dedit.php','customerNumber=" . $keyvalue . "','dynamic' )\">Click Here</a>");
		}	
	
}

?>